#!/usr/bin/perl
# user_log.cgi
# Display the USERLOG

require './naslog-lib.pl';
require './show_log.pl';

$access{'user'} || &error($text{'userlog_ecannot'});
&header($text{'user_title'},undef,"index",undef,0);

` ./userlog.pl | sort -k2,3 >>$config{'user_log'} `;

open(FH,$config{'user_log'});
@niu = <FH>;
@niu2 = reverse (@niu);
close(FH);
print "<table width=100%>";

print "<tr>";
print "<td>";

print "<div class=main>"; 
print "<table class=mode1 border=0 cellspacing=0 cellpadding=0 width='100%'>\n";
print "<tr class=title1>";
print "<td width=%12 ><b>$text{'table_user'}</b></td>";
print "<td width=%12 ><b>$text{'table_node'}</b></td>";
print "<td width=%12 ><b>$text{'table_type'}</b></td>";
print "<td width=%34 ><b>$text{'table_event'}</b></td>";
print "<td width=%15 ><b>$text{'table_date'}</b></td>";
print "<td width=%15 ><b>$text{'table_time'}</b></td>";
print "</tr>\n";
print "<form method=post onsubmit='return onsubmit_form();'>";
print "<input type=hidden name=log value='user_log' >";
$m=2;
foreach(@niu2){
	/(\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (.*)/;
	$type=$1;
	$date=$2;
	$time=$3;
	$user=$4;
	$node=$5;
	$event=$6;
	$object=$7;

	if($user eq '?') { $user=$text{'unknown_user'}; } 
	elsif($user eq 'anonymous') { $user=$text{'anonymous'}; } 

	$m = ( $m==2 ? 1:2 );
	print "<tr class=mode$m>";
	print "<td>$user</td>";
	print "<td>$node</td>";
	print "<td>$type</td>";
	print "<td>$text{$event} $object</td>";
	print "<td>$date</td>";
	print "<td>$time</td>";
	print "</tr>\n";
}
#close(FH);

print "</TABLE>";
print "</div>";
print "</td>";

print "<td valign=top width=120>";
print "<table width=100% cellpadding=4>";

#print "<tr><td>&nbsp;</td></tr>";

print "<tr><td>";
print "<input type=submit name=download class=button ";
print " value='$text{'download_log'}' onclick='download_log();'>";
print "</td></tr>";

print "<tr><td>";
print "<input type=submit name=setup class=button ";
print " value='$text{'log_properties'}' onclick='log_properties();'>";
print "</td></tr>";

print "<tr><td>";
print "<input type=submit name=clear class=button ";
print " value='$text{'clear_log'}' onclick='clear_log();' $disable >";
print "</td></tr>";
print "</form>";

print "<tr height=100%><td>&nbsp;</td></tr>";

print "</table>";
print "</td>";
print "</tr>";
print "</table>";

print <<EOF;
<script>
function log_properties()
{
	document.forms[0].action="log_properties.cgi";
}

function download_log()
{
	document.forms[0].action="download_log.cgi";
}

function clear_log()
{
	if (!confirm("$text{'clear_log_confirm'}")) return false;
	document.forms[0].action="clear_log.cgi";
}
function onsubmit_form()
{
        document.forms[0].download.disabled = true;
        document.forms[0].setup.disabled = true;
        document.forms[0].clear.disabled = true;
}

</script>
EOF


&footer("", $text{'index_return'});

